package cn.pugle.oj.leetcode;

import cn.pugle.oj.catalog.ArrayProblem;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/move-zeroes/
 *
 * @author tzp
 * @since 2020/10/15
 */
public class LC283 implements ArrayProblem {

    public void moveZeroes(int[] nums) {
        if (nums == null || nums.length == 0) return;
        for (int lastNonZeroFoundAt = 0, cur = 0; cur < nums.length; cur++) {
            if (nums[cur] != 0) {
                swap(nums, lastNonZeroFoundAt++, cur);
            }
        }
    }

    public void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
        System.out.println("swap");
    }

    public static void main(String[] args) {
        int[] a = {0, 1, 0, 3, 12};
        new LC283().moveZeroes(a);
        System.out.println(Arrays.toString(a));
    }
}
